home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 58678 / 58678.xpi / components / clipple-loader.js
Text File  |  2010-01-09  |  4KB  |  144 lines

  1. /**
  2.  * @fileOverview
  3.  * @name clipple-loader.js
  4.  * @author mooz <stillpedant@gmail.com>
  5.  * @license The MIT License
  6.  */
  7.  
  8. const Cc = Components.classes;
  9. const Ci = Components.interfaces;
  10. const prefService = Cc['@mozilla.org/preferences;1'].getService(Ci.nsIPrefBranch);
  11.  
  12. const CID = Components.ID('{2949016c-3e8c-4726-988c-6bd2c90f3e8e}');
  13. const CONTRACT_ID = '@github.com/mooz/clipple/loader;1';
  14. const CLASS_NAME = 'clipple Loader';
  15.  
  16. const STARTUP_TOPIC = 'app-startup';
  17.  
  18. function message(aMsg) {
  19.     let logs = Cc["@mozilla.org/consoleservice;1"].getService(Ci.nsIConsoleService);
  20.  
  21.     try
  22.     {
  23.         logs.logStringMessage(aMsg);
  24.     }
  25.     catch (x)
  26.     {
  27.         logs.logStringMessage(x);
  28.     }
  29. }
  30.  
  31. function list(aObject) {
  32.     if (!aObject)
  33.     {
  34.         message("listProperty: undefined object passed");
  35.     }
  36.     else
  37.     {
  38.         try
  39.         {
  40.             for (let property in aObject)
  41.                 message("[" + property + "] = " + aObject[property] );
  42.         }
  43.         catch (x)
  44.         {
  45.             message(x);
  46.         }
  47.     }
  48. }
  49.  
  50. let js = Cc["@mozilla.org/moz/jssubscript-loader;1"]
  51.     .getService(Ci.mozIJSSubScriptLoader);
  52.  
  53. function loadModule(aName, aContext) {
  54.     js.loadSubScript("chrome://clipple/content/" + aName + ".js", aContext);
  55. }
  56.  
  57. // ====================================================================== //
  58.  
  59. function ClippleLoader() {
  60. }
  61.  
  62. ClippleLoader.prototype = {
  63.     observe: function (aSubject, aTopic, aData) {
  64.         switch (aTopic)
  65.         {
  66.         case STARTUP_TOPIC:
  67.             Cc['@mozilla.org/embedcomp/window-watcher;1'].getService(Ci.nsIWindowWatcher).registerNotification(this);
  68.             break;
  69.         case 'domwindowopened':
  70.             aSubject.addEventListener('load', this, false);
  71.             break;
  72.         }
  73.     },
  74.  
  75.     handleEvent: function (aEvent) {
  76.         aEvent.currentTarget.removeEventListener('load', this, false);
  77.  
  78.         let doc = aEvent.target;
  79.         let win = doc.defaultView;
  80.  
  81.         loadModule("clipple", win);
  82.     },
  83.  
  84.     QueryInterface: function (aIID) {
  85.         if (!aIID.equals(Ci.nsIDOMEventListener) &&
  86.             !aIID.equals(Ci.nsIObserver) &&
  87.             !aIID.equals(Ci.nsISupports)) {
  88.             throw Components.results.NS_ERROR_NO_INTERFACE;
  89.         }
  90.         return this;
  91.     }
  92. };
  93.  
  94. var module = {
  95.     registerSelf: function (aCompMgr, aFileSpec, aLocation, aType) {
  96.         aCompMgr = aCompMgr.QueryInterface(Ci.nsIComponentRegistrar);
  97.         aCompMgr.registerFactoryLocation(CID,
  98.                                          CLASS_NAME,
  99.                                          CONTRACT_ID,
  100.                                          aFileSpec,
  101.                                          aLocation,
  102.                                          aType);
  103.         var catMgr = Cc['@mozilla.org/categorymanager;1'].getService(Ci.nsICategoryManager);
  104.         catMgr.addCategoryEntry(STARTUP_TOPIC, CLASS_NAME, CONTRACT_ID, true, true, null);
  105.     },
  106.  
  107.     unregisterSelf: function (aCompMgr, aLocation, aType) {
  108.         aCompMgr = aCompMgr.QueryInterface(Ci.nsIComponentRegistrar);
  109.         aCompMgr.unregisterFactoryLocation(CLASS_ID, aLocation);
  110.     },
  111.  
  112.     getClassObject: function (aCompMgr, aCID, aIID) {
  113.         if (!aIID.equals(Ci.nsIFactory))
  114.         {
  115.             throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
  116.         }
  117.  
  118.         if (!aCID.equals(CID))
  119.         {
  120.             throw Components.results.NS_ERROR_NO_INTERFACE;
  121.         }
  122.  
  123.         return this.factory;
  124.     },
  125.  
  126.     canUnload: function (aCompMgr) {
  127.         return true;
  128.     },
  129.  
  130.     factory: {
  131.         createInstance: function (aOuter, aIID) {
  132.             if (aOuter != null)
  133.             {
  134.                 throw Components.results.NS_ERROR_NO_AGGREGATION;
  135.             }
  136.             return (new ClippleLoader()).QueryInterface(aIID);
  137.         }
  138.     }
  139. };
  140.  
  141. function NSGetModule(aCompMgr, aFileSpec) {
  142.     return module;
  143. }
  144.